<?php
/**
 * Created by PhpStorm.
 * User: cephei
 * Date: 12/12/15
 * Time: 10:44 AM
 */

namespace Plugins\DeliverHub;


use Core\PluginContainer;
use Smtp\Smtp;

class Plugin_DeliverHub
{
    private $db;

    private $mailUserName='cephei@yeah.net';

    private $mailUserPassWord='163.!@#wwj456212';

    public function __construct()
    {
        $this->db = PluginContainer::getInstance()->singletonMake('database');
    }

    /*
     * @param level G = 1;PG = 2;G_13 = 3;R = 4;NC_17 = 5;NR = 9;
     */
    public function sendMessage($type, $level, $message)
    {
        $userList = PluginContainer::getInstance()->make('user')->selectUserByLevel($level);
        foreach($userList as $user){
            switch($type){
                case 'mail':
                    $smtp = new Smtp(true,$this->mailUserName,$this->mailUserPassWord);
                    $smtp->debug = false;
                    $smtp->sendmail($user->mail,$this->mailUserName,$message["title"],$message["content"],$message["type"]);
                    break;
            }
        }
    }
}